<template>
  <div class="floorChange">
    <div
      :class="['floorBtn',{
          isActive:floor.isActive,
          isPositionFloor: floor.isPositionFloor
      }]"
      v-for="(floor,index) in floorData"
      :key="index"
      @click="changeFloor(floor)"
    >
      <div class="floorName">{{floor.name}}</div>
      <div class="floorLabel" v-if="floor.isPositionFloor">您所在楼层</div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    floorData: {
      type: Array,
      required: true
    }
  },
  data() {
    return {};
  },
  computed: {},
  created() {},
  mounted() {
    if (map) {
      map.regFloorChange(floorIDs => {
        this.updateFloorStyle(floorIDs[0]);
      });
    }
  },
  watch: {},
  methods: {
    // 切换楼层
    changeFloor(floor) {
      console.log('floor', floor)
      if (floor.isActive) {
        return;
      }
      this.updateFloorStyle(floor.floorID);
      map.showFloors([floor.floorID]);
      this.$parent.resetMap();
    },
    // 更新楼层按钮显示样式
    updateFloorStyle(floorID) {
      this.floorData.forEach(item => {
        item.isActive = false;
        if (item.floorID === floorID) {
          item.isActive = true;
        }
      });
    }
  },
  components: {}
};
</script>

<style scoped lang='less'>
.floorChange {
  position: absolute;
  left: 35px;
  top: 50%;
  transform: translateY(-50%);
  width: 84px;
  background-color: #fef9f2;
  border-radius: 42px;
  padding: 50px 0;
  display: flex;
  flex-direction: column;
  .floorBtn {
    width: 100%;
    display: flex;
    height: 105px;
    flex-direction: column;
    justify-items: center;
    align-items: center;
    cursor: pointer;
    .floorName {
      width: 75px;
      height: 75px;
      border-radius: 50%;
      line-height: 75px;
      font-size: 30px;
      letter-spacing: 2px;
      color: #bd975a;
      text-align: center;
      transition: all 0.5s;
    }
    .floorLabel {
      margin-top: 10px;
      width: 100%;
      text-align: center;
      font-size: 14px;
      letter-spacing: 1px;
      color: #8d6518;
      transition: all 0.3s;
    }
    &.isPositionFloor {
      .floorName {
        background-color: #e6ce9e;
        color: #fff;
      }
    }
    &.isActive {
      .floorName {
        background-color: #cbab6c;
        color: #fff;
      }
    }
  }
}
</style>
